import os
from opencc import OpenCC

def convert_filenames_to_simplified(directory='.'):
    cc = OpenCC('t2s')  # 繁体到简体转换器
    
    for root, dirs, files in os.walk(directory):
        for file in files:
            # 构建完整的文件路径
            old_file_path = os.path.join(root, file)
            # 转换文件名
            new_file_name = cc.convert(file)
            # 新的文件路径
            new_file_path = os.path.join(root, new_file_name)
            
            # 如果文件名发生了变化，执行重命名
            if new_file_name != file:
                os.rename(old_file_path, new_file_path)
                print(f"Renamed '{file}' to '{new_file_name}'")

if __name__ == "__main__":
    import sys
    
    # 获取命令行参数，如果没有则默认使用当前目录
    directory = sys.argv[1] if len(sys.argv) > 1 else '.'
    
    convert_filenames_to_simplified(directory)
    os.system('pause')